@extends('admin::layouts.master')
@section('title')
    添加道路救援商铺
@endsection
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row">

            <form class="layui-form">

                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>门店名称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" name="name" required="" maxlength="50" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>公司名称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="company_name" name="company_name" maxlength="50" required="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>老板姓名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="name_boss" name="name_boss" maxlength="20" required="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>手机号
                    </label>
                    <div class="layui-input-inline">
                        <input lay-verify="required|phone|number" type="text" id="phone" name="phone" required="" maxlength="11" autocomplete="off" class="layui-input">
                    </div>
                </div>




{{--                <div class="layui-form-item">--}}
{{--                    <label for="L_pass" class="layui-form-label">--}}
{{--                        <span class="x-red">*</span>密码--}}
{{--                    </label>--}}
{{--                    <div class="layui-input-inline">--}}
{{--                        <input type="password" id="L_pass" name="pass" maxlength="20" required="" autocomplete="off" class="layui-input">--}}
{{--                    </div>--}}
{{--                    <div class="layui-form-mid layui-word-aux">--}}
{{--                        密码必须同时包含数字和字母的6-18位字符！--}}
{{--                    </div>--}}
{{--                </div>--}}
{{--                <div class="layui-form-item">--}}
{{--                    <label for="L_repass" class="layui-form-label">--}}
{{--                        <span class="x-red">*</span>确认密码--}}
{{--                    </label>--}}
{{--                    <div class="layui-input-inline">--}}
{{--                        <input type="password" id="L_repass" name="repass" required="" autocomplete="off" class="layui-input">--}}
{{--                    </div>--}}
{{--                </div>--}}

                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn" lay-filter="add" lay-submit="">增加</button></div>
            </form>
        </div>
    </div>
@endsection
@section('tab_js')
    <script>

        function check_form_data($_data){
            if($_data.name.length <= 0){
                return {state:1,msg:'请填写门店名称',font:{}};
            }

            if($_data.company_name.length <= 0){
                return {state:1,msg:'请填写公司名称',font:{}};
            }

            if($_data.name_boss.length <= 0){
                return {state:1,msg:'请填写老板姓名',font:{}};
            }

            if($_data.phone.length <= 0){
                return {state:1,msg:'请填写手机号',font:{}};
            }
            //
            // if($_data.pass.length <= 0){
            //     return {state:1,msg:'请填写密码',font:{}};
            // }
            // if ($_data.repass !== $_data.pass) {
            //     return {state:1,msg:'两次密码不一致',font:{time:2000,icon: 5}};
            // }

            return {state:0,msg:'成功',font:{}};

        }

        layui.use(['form', 'layer','jquery'],
            function() {

                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;
                // form.render('select');//重新渲染下拉框

                //监听提交
                form.on('submit(add)',
                    function(data) {
                        var $_url = '{{route('admin_shop_road_help_add')}}';
                        var $_data = data.field;
                        var $_result = check_form_data($_data);
                        if($_result.state !== 0){
                            layer.msg($_result.msg,$_result.font);
                            return false;
                        }

                        // delete $_data.repass;

                        $.ajax({
                            url:$_url,
                            type:'post',
                            data:$_data,
                            dataType : "json",
                            success:function(result){
                                if(result.state === 0){
                                    layer.msg(
                                        "增加成功",
                                        {icon: 6},
                                        function() {
                                            //关闭当前frame
                                            xadmin.close();

                                            // 可以对父窗口进行刷新
                                            xadmin.father_reload();
                                        });
                                }else{
                                    layer.msg(result.msg, {time:2000,icon: 5});
                                }

                            }});
                        return false;

                    });

            });
    </script>
@endsection




